import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class TankWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class TankWorld extends World
{

    private static final int WORLD_WIDTH = 900;
    private static final int WORLD_HEIGHT = 600;
    private static final int CELL_SIZE = 1;
    
    /**
     * State in which the game is at the start menu
     */
    public static final int START = 0;
    
    /**
     * State in which the game is at the help menu
     */
    public static final int HELP = 1;
    
    /**
     * State in which the game is re-trying the current level
     */
    public static final int TRY_AGAIN = 2;
    
    /**
     * State in which the game is currently being played by the player
     */
    public static final int IN_GAME = 3;
    
    /**
     * State in which the game is paused
     */
    public static final int PAUSED = 4;
    
    /**
     * 
     * State in which the game is at the victory screen
     */
    public static final int VICTORY = 5;
    
    /**
     * State in which the game is at the game over screen
     */
    public static final int GAMEOVER = 6;
    
    /**
     * State in which the game is at the credits screen
     */
    public static final int CREDIT = 7;
    private int state;
    
    private int currentLevel = 1;
    /**
     * Constructor for objects of class TankWorld.
     * 
     */
    public TankWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(WORLD_WIDTH, WORLD_HEIGHT, CELL_SIZE); 
        /*
        //Shasha
        prepare();
        //Shasha: MyTank always appear on top of the Bullet
        setPaintOrder(MyTank.class, Bullet.class);
        */
        addObject(new Start(), WORLD_WIDTH/2, WORLD_HEIGHT/2);
        //Shasha: MyTank always appear on top of the Bullet. Please don't remove this code
        setPaintOrder(MyTank.class, Bullet.class);
        
       
        
    }
    
    //Shasha
    public void prepare()
    {
        MyTank mytank = new MyTank();
        addObject(mytank, 80, 80);
        placeEnemyTank();
        /*addObject(new EnemyTank(), 100, 150);
        addObject(new EnemyTank(), 200, 200);
        addObject(new EnemyTank(), 300, 250);*/
    }
    
    //Shreya
    public void placeEnemyTank()
    {
        for (int i = 0; i <= 3; i++)
        {
            int x = Greenfoot.getRandomNumber(getWidth());
            int y = Greenfoot.getRandomNumber(getHeight());
            addObject(new EnemyTank(), x, y);
        }
    }
    
    /**
     * Switches the games level by adding a level object of the appropriate level number.
     * 
     * @param whichLvl The level number to switch to.
     */
    /*public void switchLevel(int whichLvl, boolean tryAgain)
    {
        cleanWorld();
        
        switch(whichLvl)
        {
            case 1: //Level one
                currentLevel = 1;
                addObject(new Level1(tryAgain), 0, 0); 
                break;   
            
            case 2: //Level two
                currentLevel = 2;
                addObject(new Level2(tryAgain), 4474, 300);
                break;

            default: 
                System.err.println("Error switching to level " + whichLvl);
        }
    }
*/
    /**
     * Returns the width of the world.
     * 
     * @return The width of the world.
     */
    public static int getWorldWidth()
    {
        return WORLD_WIDTH;
    }

    /**
     * Returns the height of the world
     * 
     * @return The height of the world.
     */
    public static int getWorldHeight()
    {
        return WORLD_HEIGHT;
    }
    
    /**
     * Checks to see if the game is paused or not.
     * 
     * @return True if game is paused and false otherwise.
     */
    public boolean isPaused()
    {
        if(state == PAUSED)
            return true;
        return false;
    }

    /**
     * Unpauses the game.
     */
    public void unPause()
    {
        state = IN_GAME;
    }
    
    /**
     * Pauses the game.
     */
    public void pause()
    {
        state = PAUSED;
    }

    private void cleanWorld()
    {
        removeObjects(getObjects(Button.class));
        removeObjects(getObjects(Screen.class));             
    }
}
